<template>
    <div class="category-nav">
        <div class="category-list">
            <div
                    v-for="category in categories"
                    :key="category.id"
                    class="category-item"
                    @click="goToCategory(category.id)"
            >
                <el-icon :size="24"><component :is="category.icon" /></el-icon>
                <div class="category-name">{{ category.name }}</div>
            </div>
        </div>
    </div>
</template>

<script>
import { useRouter } from 'vue-router'

export default {
    props: {
        categories: {
            type: Array,
            required: true
        }
    },
    setup() {
        const router = useRouter()

        const goToCategory = (categoryId) => {
            router.push({ path: '/category', query: { id: categoryId } })
        }

        return {
            goToCategory
        }
    }
}
</script>

<style scoped>
.category-nav {
    width: 200px;
    margin-right: 20px;
    background: white;
    border-radius: 4px;
    padding: 15px 0;
    flex-shrink: 0;
}

.category-list {
    display: flex;
    flex-direction: column;
}

.category-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.3s;
}

.category-item:hover {
    background-color: #fff6f6;
    color: var(--primary-color);
}

.category-item .el-icon {
    margin-right: 10px;
    color: #666;
}

.category-item:hover .el-icon {
    color: var(--primary-color);
}

.category-name {
    font-size: 14px;
}
</style>